Useful Code Snippets

Here are some code snippets I use frequently that I find useful.

JavaScript

Output the entire DOM in a React unit test:

screen.debug(undefined, Infinity);

Output stringified JSON in the console in JavaScript:

console.log(JSON.stringify(YOUR_THING_HERE, null, 4));

Git

Delete a Git commit but keep the changes:

git reset HEAD^

Modify an existing, unpushed, Git commit message:

git commit --amend -m "New commit message"

Reset developer branch to main using Git (make sure the main branch is up-to-date locally first):

git reset --hard main